﻿@using Newtouch.Infrastructure;
@{
    Layout = "~/Views/Shared/_Index.cshtml";

    var isEditPatientMedicalRecord = ViewBag.IsEditPatientMedicalRecord as bool?;
    var opr = Newtouch.Common.Operator.OperatorProvider.GetCurrent();
    //医保所属地
    var medicalInsurance = SysConfigReader.String("Outpatient_MedicalInsurance");
}
<style>
    @@media screen and (min-width:600px) {
        #btn_ {
            width: 160px;
        }

        .form .formTitle {
            width: 55px;
        }

        .form .formValue {
            width: 100px;
        }
    }

    @@media screen and (min-width:1000px) {
        .form .formTitle {
            width: 25px;
        }

        .form .formValue {
            width: 60px;
        }
    }
</style>
<form>
    <div class="panel panel-default">
        <div class="panel-heading navb-bg">
            筛选条件
        </div>
        <table class="form">
            <tr>
                @*<th class="formTitle">病历号：</th>
        <td class="formValue">
            <input type="text" class="form-control form-an" id="blh" />
        </td>*@
                <th class="formTitle">关键字：</th>
                <td class="formValue">
                    <input type="text" class="form-control form-an" id="zjh" placeholder="姓名/拼音/病历号/证件号"/>
                </td>
                <td class="formTitle">
                    <input type="button" id="btn_search" class="btn btn-md btn-primary form-an"  value="查询" />
                </td>

                <td class="formValue">
                     @Html.Partial("YibaoRedCardCommon")
                    &nbsp;&nbsp;
                    
                </td>
                <th class="formTitle">
                    <button type="button" class="btn btn-primary" id="noCardRes" value="一卡通办理" onclick="btn_NocardRes(1)">一卡通办理</button>
                   
                </th>
                <td class="formValue">
                    <input type="button" id="btn_qy" class="btn btn-md btn-primary form-an " value="一卡通启用" />
                    <input type="button" id="btn_stop" class="btn btn-md btn-primary form-an" value="一卡通停用" />
                </td>
                <th class="formTitle"></th>
                <td class="formValue"></td>
            </tr>
        </table>
        <div class="panel-heading navb-bg">
            患者基本信息
        </div>
        <table class="form">
            <tr>
                <th class="formTitle">姓名：</th>
                <td class="formValue" style="width:80px;">
                    <label id="xm"></label>
                </td>
                <th class="formTitle">性别：</th>
                <td class="formValue">
                    <label id="xb"></label>
                </td>
                <th class="formTitle">年龄：</th>
                <td class="formValue">
                    <label id="nl"></label>
                </td>
                <td class="formTitle">初复诊：</td>
                <td class="formValue">
                    <label id="cfz"></label>
                </td>

            </tr>
            <tr>
                <td class="formTitle">
                    证件号：
                </td>
                <td class="formValue">
                    <label id="lbzjh"></label>
                </td>
                <td class="formTitle">
                    出生日期：
                </td>
                <td class="formValue">
                    <label id="csrq"></label>
                </td>
                <td class="formTitle">
                    联系电话：
                </td>
                <td class="formValue">
                    <label id="lxdh"></label>
                </td>
                <td class="formTitle">
                    地址：
                </td>
                <td class="formValue">
                    <label id="dz"></label>
                </td>
            </tr>
        </table>
        <div class="panel-heading navb-bg">
            患者列表
        </div>
        <div class="gridPanel">
            <table id="gridList"></table>
            <div id="gridPager"></div>
        </div>
    </div>

</form>
@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel
{
    ShowKeyList = new int[] { 6 },
    F6Hidden = !(isEditPatientMedicalRecord.Value),
    F6Text = "历史病历",
})
<script>
    var medicalInsurance = '@medicalInsurance';//医保所属地配置:区分医院所属医保区域
    $(function () {
        $("#readCard").show();
        //$("#btkhsr").css('display', 'none');
        gridList();

        $("#blh").keyupEnterEvent(function () {
            $("#btn_search").trigger("click");
        });
    });
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/PatientManage/HospiterRes/GetGridJson",
            postData: getSearchPostData(),
            height: $(window).height() - @(!(isEditPatientMedicalRecord.Value) ? "200" : "190"),
            colModel: [
                { label: 'patId', name: 'patId', width: 100, align: 'left', hidden: true },
                { label: 'CardId', name: 'CardId', width: 100, align: 'left', hidden: true },
                { label: '姓名', name: 'xm', width: 80, align: 'left' },
                { label: '病历号', name: 'blh', width: 80, align: 'left' },
                //{ label: '患者性质', name: 'brxzmc', width: 120, align: 'left' },
                //{ label: '卡类型', name: 'cardTypeName', width: 120, align: 'left' },
                {
                    label: '性别', name: 'xb', width: 50, align: 'left',
                    formatter: function (cellvalue) {
                        return $.getGender(cellvalue);
                    }
                },
                { label: '证件号', name: 'zjh', width: 160, align: 'left' },

                 { label: 'cardType', name: 'cardType', width: 160, align: 'left', hidden: true  },
                { label: '患者来源', name: 'brly', width: 80, align: 'left' },
                {
                    label: '出生年月', name: 'csny', width: 100, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
                },
                { label: '创建时间', name: 'CreateTime', width: 160, align: 'left',formatter: "date", formatoptions: {
                    srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                },
                { label: "有效", name: "zt", width: 60, align: "center", formatter: function (cellvalue) { return cellvalue == "1" ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>"; } },
                {
                    label: "卡管理", name: "", width: 100, align: 'center', formatter(val, option, row) {

                        return "<a class='btn btn-default' style='width:60px;font-weight:bold;textalign:center;' onclick='CardNoInfo(" + option.rowId + ")'>就诊卡管理</a>";

                    }
                }
            ],
            pager: "#gridPager",
            sortname: 'createtime desc',
            rowNum: '10',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            clear();
            //if($("#zjh").val())
            //{
            //    GetQueryFphAjax({
            //        blh: null,
            //        kh: null,
            //        zjh: $("#zjh").val(),
            //        ly:'Y',
            //    });
            //}
            $gridList.jqGrid('setGridParam', {
                postData: getSearchPostData(),
                page: 1,
            }).trigger('reloadGrid');

        });
    }

    //查询条件
    function getSearchPostData() {
        var zjh=$("#zjh").val();
        return {zjh: zjh};

    }

    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "住院登记",
            url: "/PatientManage/HospiterRes/Register",
            width: "700px",
            height: "530px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function btn_edit() {
        var patientform = JSON.parse(localStorage.getItem("patientform"));
        if (!!patientform) {
            localStorage.removeItem("patientform");
        }
        var keyValue = $("#gridList").jqGridRowValue().patId;
        if(!!!keyValue){
            return;
        }
        $.modalOpen({
            id: "Details",
            title: "查看/修改一卡通信息",
            url: "/PatientManage/HospiterRes/PatientBasic?keyValue=" + keyValue+"&parent=patientlist"+"&fromly=yktmodify",
            width: "1050px",
            height: "550px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    $('#btn_qy').click(function () {
        var seleRow = check();
        if (!!!seleRow) {
            return;
        }
        var patId=seleRow.patId;
        updateZt(patId,"1");
    });
    $('#btn_stop').click(function () {
        var seleRow = check();
        if (!!!seleRow) {
            return;
        }
        var patId=seleRow.patId;
        updateZt(patId,"0");
    });

    function updateZt(patId,isqy)
    {
        $.ajax({
            type: "POST",
            url: "/PatientManage/HospiterRes/UpdateZt",
            data: {"patId":patId,"isqy":isqy},
            dataType: "json",
            async: true,
            success: function (resp) {
                $("#btn_search").trigger("click");
                $.modalAlert("修改成功", 'warning');
            }
        });
    }

    function check() {
        var seleRow = $("#gridList").jqGridRowValue();
        var patId = seleRow.patId;
        if (!!!patId) {
            $.modalAlert("尚未选择一条记录", "error");
            return;
        }
        return seleRow;
    }

    function btn_NocardRes(t){
        debugger;
        var patientform = JSON.parse(localStorage.getItem("patientform"));
        if(t!=null&&t===1)
        {
            localStorage.removeItem("patientform");
        }
        var url="/PatientManage/HospiterRes/PatientBasic?T=" + new Date()+ "&parent=patientlist"+"&fromly=yktregister";
        if(t!=1)
        {
            url+="&keyValue=" + t;
        }
        $.modalOpen({
            id: "Form",
            title: "一卡通办理",
            url: url,
            width: "1050px",
            height: "550px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });

    }

    function btn_selfPayCard()
    {
        $.modalAlert("功能开发中", "warning");
    }
    function CallbackPatientQuery(blh) {
        //GetQueryFphAjax({ blh: blh });
    }

    function newtouch_event_f6(){
        var keyValue = $("#gridList").jqGridRowValue().blh;
        if(!!!keyValue){
            $.modalAlert("请选择一个患者", "warning");
            return;
        }
        $.modalOpen({
            id: "PatientMedicalRecordList",
            title: "患者历史病历",
            url: "/PatientManage/SysPatientMedicalRecord/Index?blh=" + keyValue,
            width: "900px",
            height: "600px",
            btn: null,
            callBack: function (iframeId) {

            }
        });
    }
    function clear()
    {
        $("#xm").html("");
        $("#xb").html("");
        $("#cfz").html("");
        $("#nl").html("");
        $("#lbzjh").html("");
        $("#csrq").html("");
        $("#lxdh").html("");
        $("#dz").html("");
    }

    ////医保业务
   
    var patModel = null;
    function GetQueryFphAjax(obj, funcSuccCallback){
        debugger;
        $.najax({
            url: "/PatientManage/HospiterRes/GetOutpatientBasicInfo",
            data: obj,
            dataType: "json",
            async: false,
            success: function (rep) {
                patModel = rep.data;
                $("#xm").html(patModel.xm);
                $("#xb").html($.getGender(patModel.xb));
                $("#cfz").html(patModel.fzbz!==0 ? '复诊':'初诊');
                $("#nl").html(getAgeFromBirthTime({ begin: patModel.csny.replace('T',' ') }).text);
                $("#lbzjh").html(patModel.zjh);
                $("#csrq").html(patModel.csny);
                $("#lxdh").html(patModel.phone);
                $("#dz").html(patModel.dz);
            },
            alertbierror: false,
            errorCallback: function (rep){
                if(rep.code === 'OUTPAT_REGIST_ISINVALID')
                {
                    $.modalConfirm("一卡通尚未登记，是否办理", function (flag) {
                        if (flag) {
                            btn_NocardRes();
                        }
                    });
                }
            }
        });
    }
    function ReadCardCall(readCardObj)
    {
        localStorage.setItem("patientform", JSON.stringify(readCardObj.yibaoCardInfo));
        GetQueryFphAjax({ blh: null, kh:  readCardObj.yibaoCardInfo.kh , zjh:  readCardObj.yibaoCardInfo.qtjz, cardType:readCardObj.ybkCardType },
                        function () {
                        });
    }  
    

    function CardNoInfo(rowid) {
        var rowdata = $('#gridList').jqGrid('getRowData', rowid);
        $.modalOpen({
            id: "LogDetailsView",
            title: "就诊卡管理",
            url: "/PatientManage/HospiterRes/CardManagement?patId=" + rowdata.patId + "&xm=" + rowdata.xm,
            width: "700px",
            height: "530px",
            btn: [],
            //callBack: function (iframeId) {
            //    top.frames[iframeId].$.modalClose();
            //}
        });
    }
</script>
